Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created PasswordInput component with visibility button (eye icon) #750

Merged
merged 49 commits into from
Sep 20, 2023

Conversation

balsa-asanovic
Copy link
Contributor

@balsa-asanovic balsa-asanovic commented Sep 13, 2023

Problem

When typing the Wi-Fi password user does not have a way to see what was actually typed in, since the password is hidden by default.

fixes #242

Solution

A new component, PasswordInput, has been created. It includes both a text input field and a visibility button with an eye icon.

When the visibility button is clicked, it toggles the text input's form type from 'password' to 'text,' making the characters visible to the user.

This component is now utilized wherever the input type 'password' was previously employed.

As of the time of writing, this applies to the following components:

src/components/storage/iscsi/AuthFields.jsx
src/components/questions/LuksActivationQuestion.jsx
src/components/network/WifiConnectionForm.jsx
src/components/core/PasswordAndConfirmationInput.jsx

Also this PR now fixes #760 after the issue was raised while making reviews here.

Testing

Added unit test for the new component in file PasswordInput.test.jsx.

Also tested manually.

Screenshots

Password input in Users menu
image
image

Wi-Fi password input
image

iSCSI storage password input
image

Luks activation question password input
image

Copy link
Contributor

@dgdavid dgdavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Balsa!

To begin with, thanks a lot for this new contribution! Clearly, it resolves #242.

There are, however, a few changes I would like to suggest:

  • Use the "eye icon pattern"

    I.e., to put an eye icon close to the password input for revealing or hiding its content. Similar to the Cockpit's login page implements it.

    An example of how to do it with PatternFly is here and you can use the "Visibility" and "Visibility off" icons provided by material symbols importing them in the Icon component.

  • Opting for a toggle action rather than a "momentary" one

    I.e., make the password input visible (or not) upon clicking.

Hope you don't mind, but I think it's a well-known, slightly better approach.

@balsa-asanovic
Copy link
Contributor Author

Hope you don't mind, but I think it's a well-known, slightly better approach.

Hey David,

Don't mind at all, in fact thank you for taking the time to point me in the right direction.

I've made some commits in accordance with your comments, so check it out and let me know if there is anything more I should do regarding this.

I noticed something that bothered me a bit but wasn't sure how to fix it—the horizontal alignment of the eye icon within the button doesn't seem quite centered; it's slightly shifted towards the top. It might not be a big deal, but I thought I'd point it out.

Testing pics:

image

image

Copy link
Contributor

@dgdavid dgdavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mind at all, in fact thank you for taking the time to point me in the right direction.

I've made some commits in accordance with your comments, so check it out and let me know if there is anything more I should do regarding this.

Wow! That was really fast! Thank you!

I've added a few comments more. Once you address them, we can continue working to go a a bit further 😇 is you're willing to do so 😉

I noticed something that bothered me a bit but wasn't sure how to fix it—the horizontal alignment of the eye icon within the button doesn't seem quite centered; it's slightly shifted towards the top. It might not be a big deal, but I thought I'd point it out.

The quick fix that comes to my mind now is to add a "display: flex" to the span.pf-c-button__icon wrapping the icon. Just add below lines to the end of src/assets/styles/patternfly-overrides.scss file

button#password_visibility span.pf-c-button__icon {
  display: flex;
}

We can go for a better solution later, once the migration to PatternFly 5 is done.

web/src/components/layout/Icon.jsx Show resolved Hide resolved
web/src/components/network/WifiConnectionForm.jsx Outdated Show resolved Hide resolved
web/src/components/network/WifiConnectionForm.jsx Outdated Show resolved Hide resolved
web/src/components/network/WifiConnectionForm.jsx Outdated Show resolved Hide resolved
@balsa-asanovic

This comment was marked as resolved.

@dgdavid
Copy link
Contributor

dgdavid commented Sep 18, 2023

Hey David,

I've went through your comments, I think I covered them all.

Nitpicking: what about using an internal component instead?

Here, I chose the second option, without the internal component. No particular reason, I've just went with the option which had a line of code less 😄 If you think that using internal component is a better choice, feel free to mention it and I'll update code accordingly.

No strong opinion from my side. Your choice is ok. Let's save lines of code until they are really needed 😉

Once you address them, we can continue working to go a a bit further 😇 is you're willing to do so 😉

Certainly, keep 'em coming. 😄

Great!

So, to be clear: from my point of view, the PR is ready to be merged as it is now. However, with very little effort, we can improve it a lot for extending that behavior to all password inputs. The idea is

  • Create a src/components/core/PasswordInput.jsx component

    • And move the logic dealing with the password input and its reveal button there.

    • By now, I'd just forward received props to the internal TextInput but overriding the ones needed, like type. Something like

      export default function PasswordInput({ props }) {
         ...
      
        return (
           <>
             <TextInput {...props} type={type} />
        ...
  • Add simple tests for that new component at src/components/core/PasswordInput.test.jsx file

  • Replace all password inputs by the new PasswordInput component to make the UI more consistent and allow the user to reveal desired password, not only these related to a WiFi network.

    ❯ grep -rl "type=\"password" src/
    src/components/storage/iscsi/AuthFields.jsx
    src/components/questions/LuksActivationQuestion.jsx
    src/components/network/WifiConnectionForm.jsx
    src/components/core/PasswordAndConfirmationInput.jsx
  • Check everything works

  • Change the PR title

  • Update the PR description

  • Adapt the changes file

Do you accept the challenge?

@dgdavid
Copy link
Contributor

dgdavid commented Sep 18, 2023

Do you accept the challenge?

Of course, you can ping us at any moment you have doubts or need help. We can even jump into the PR for writing the unit test if you get stuck there.

@balsa-asanovic
Copy link
Contributor Author

Do you accept the challenge?

Accepted, I'll get on it. Also thanks for the pointers, they certainly help a lot.

@imobachgs

This comment was marked as resolved.

@joseivanlopez
Copy link
Contributor

joseivanlopez commented Sep 19, 2023

I'm just not sure if using this widget makes sense in the first screenshot. The one with "password" and "password confirmation". It makes a lot of sense in all the others (iSCSI and WiFi), in which you are providing a previously set password. But I find combining a "password confirmation" with a password reveal to be weird.

Just my 2 cents about this topic. The "password confirmation" ensures you have typed the same in both inputs, and the "visibility icon" allows you to check you have typed what you really wanted. For me they are complementary. And IMHO, the "visibility icon" is even more important than the confirmation input. Reading the password is the safest way to check that I have really entered it correctly . In fact, having a confirmation is usually useless for me. Many times I write the password correctly but the confirmation wrongly. So having only the password input and the option to read it would be even faster and more secure for me.

And using autogenerated password would make the confirmation even more useless (you probably copy-paste in both inputs :-P).

It is only a reflection. I am not suggesting to do this ;-).

@balsa-asanovic
Copy link
Contributor Author

Believe me, I don't want to bother you with the code-review and suggestions. Far from it. However, I requested a new set of changes 😅 😅 😅

Haha, why not, glad to clean up 😄

I think I covered all suggested changes.
Regarding the unit tests where you believed they are probably tested as a part of components' library, I removed them.

Also, I addressed #760 while working on PasswordConfirmation component, so split prop is gone along with its wrapper.

Additionally, with the help of @joseivanlopez comment

I think the easiest way is to encrypt any device (disk or partition). If you are using a virtual machine, you can simply add a new disk (e.g., /dev/sdb) and then run the following command:

cryptsetup -y -v luksFormat /dev/sdb

After that, restart Agama (or change the product in the product selection page) and the encryption password popup should be shown.

Note: if you either skip or introduce the correct password, then the dialog is not shown anymore (you have to restart Agama to see it again).

I succeeded in reaching Luks Activation Question component and testing the password input.
Attached screenshots for this in PR description.

@balsa-asanovic

This comment was marked as resolved.

@balsa-asanovic

This comment was marked as resolved.

Copy link
Contributor

@dgdavid dgdavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balsa-asanovic

From my point of view, it looks pretty good now. Thanks a lot for such a GREAT job

I've added a few minor suggestions, but the PR is ok as it is.

Also thanks to @nobkd for reviewing and contributing to make the PR even better.

web/src/components/core/PasswordInput.jsx Outdated Show resolved Hide resolved
web/src/components/core/PasswordInput.jsx Show resolved Hide resolved
web/src/components/core/PasswordInput.jsx Show resolved Hide resolved
web/src/components/core/PasswordInput.jsx Outdated Show resolved Hide resolved
made id prop required, logging to console if it's not provided
@balsa-asanovic
Copy link
Contributor Author

Thanks a lot for such a GREAT job

Don't mention it, anytime.

Added documentation comments and extracted the id prop.

@dgdavid dgdavid merged commit 0c12b1c into agama-project:master Sep 20, 2023
5 checks passed
@balsa-asanovic balsa-asanovic deleted the wifi-password-show-button branch September 20, 2023 12:55
@imobachgs imobachgs mentioned this pull request Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants